/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2012
 */

package com.hibernate.model;


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.javacommon.base.BaseEntity;
import org.hibernate.validator.constraints.Length;

/**
 * @author badqiu email:badqiu(a)gmail.com
 * @version 1.0
 * @since 1.0
 */


@Entity
@Table(name = "CATEGORY_INFO_MAP")
public class CategoryInfoMap extends BaseEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;
	
	//alias
	public static final String TABLE_ALIAS = "CategoryInfoMap";
	public static final String ALIAS_ID = "ID";
	public static final String ALIAS_USER_ID = "用户id";
	public static final String ALIAS_NAME = "分类名称";
	public static final String ALIAS_CATEGORY_STR = "类别id 拼成的字符串";
	
	//date formats
	

	//可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	//columns START
    /**
     * ID       db_column: ID 
     */ 	
	
	private Long id;
    /**
     * 用户id       db_column: USER_ID 
     */ 	
	
	private java.lang.Long userId;
    /**
     * 分类名称       db_column: NAME 
     */ 	
	@Length(max=20)
	private java.lang.String name;
    /**
     * 类别id 拼成的字符串       db_column: CATEGORY_STR 
     */ 	
	@Length(max=500)
	private java.lang.String categoryStr;
	
	@Transient
	private String categoryNameStr;
	
	/** 
	 * propertyValue对应数据库中的NAME字段
	 * 众易投合并后，使用category_info_map表，map表没有propertyValue字段，
	 * 为减少修改，直接在此处对应到数据库中的NAME字段，后续再做调整 
	 */
	private String propertyValue;

	//columns END


	public CategoryInfoMap(){
	}

	public CategoryInfoMap(
			Long id
	){
		this.id = id;
	}

	

	public void setId(Long value) {
		this.id = value;
	}
	
	@Id
	@GeneratedValue(generator = "paymentableGenerator")       
	@GenericGenerator(name = "paymentableGenerator", strategy = "native") 
	@Column(name = "ID", unique = true, nullable = false, insertable = true, updatable = true, length = 10)
	public Long getId() {
		return this.id;
	}
	
	@Column(name = "USER_ID", unique = false, nullable = true, insertable = true, updatable = true, length = 19)
	public java.lang.Long getUserId() {
		return this.userId;
	}
	
	public void setUserId(java.lang.Long value) {
		this.userId = value;
	}
	
	@Column(name = "NAME", unique = false, nullable = true, insertable = true, updatable = true, length = 20)
	public java.lang.String getName() {
		return this.name;
	}
	
	public void setName(java.lang.String value) {
		this.name = value;
	}
	
	@Column(name = "CATEGORY_STR", unique = false, nullable = true, insertable = true, updatable = true, length = 500)
	public java.lang.String getCategoryStr() {
		return this.categoryStr;
	}
	
	public void setCategoryStr(java.lang.String value) {
		this.categoryStr = value;
	}
	
	@Column(name = "NAME", unique = false, nullable = true, insertable = false, updatable = false, length = 20)
	public String getPropertyValue() {
		return propertyValue;
	}
	
	public void setPropertyValue(String propertyValue) {
		this.propertyValue = propertyValue;
	}
	private AcctUser acctUser;
	public void setAcctUser(AcctUser acctUser){
		this.acctUser = acctUser;
	}
	
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumns({
		@JoinColumn(name = "USER_ID",nullable = false, insertable = false, updatable = false) 
	})
	public AcctUser getAcctUser() {
		return acctUser;
	}
	
	public String toString() {
		return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
			.append("Id",getId())
			.append("UserId",getUserId())
			.append("Name",getName())
			.append("CategoryStr",getCategoryStr())
			.toString();
	}
	
	public int hashCode() {
		return new HashCodeBuilder()
			.append(getId())
			.toHashCode();
	}
	
	public boolean equals(Object obj) {
		if(obj instanceof CategoryInfoMap == false) return false;
		if(this == obj) return true;
		CategoryInfoMap other = (CategoryInfoMap)obj;
		return new EqualsBuilder()
			.append(getId(),other.getId())
			.isEquals();
	}
	
	public void setCategoryNameStr(String categoryNameStr) {
		this.categoryNameStr = categoryNameStr;
	}
	@Transient
	public String getCategoryNameStr() {
		return categoryNameStr;
	}
	@Transient
	@Override
	public String getTarget() {
		// TODO Auto-generated method stub
		return "类目映射";
	}
	@Transient
	@Override
	public Long getTargetId() {
		// TODO Auto-generated method stub
		return (long)getId();
	}

	@Transient
	@Override
	public String getTargetName() {
		// TODO Auto-generated method stub
		return getName();
	}
}

